package com.hanbang.maige.pressenter.huodong;

import com.hanbang.maige.code.base.presenter.BasePresenter;
import com.hanbang.maige.mode.HttpRequest;
import com.hanbang.maige.mode.httpresponse.BaseHttpResponse;
import com.hanbang.maige.mode.httpresponse.HttpResult;
import com.hanbang.maige.mode.javabean.huodong.HuoDongDetailData;
import com.hanbang.maige.utils.http.httpquest.HttpCallBack;
import com.hanbang.maige.utils.http.httpquest.HttpRequestParam;
import com.hanbang.maige.view.huodong.IHuoDongBaseView;

/**
 * Created by Administrator on 2016/10/26.
 */

public class HuoDongDetailPresenter extends BasePresenter<IHuoDongBaseView.IHuoDongDetailView> {

    /**
     * 作者　　: 李坤
     * 创建时间: 2016/10/26 14:33
     * <p>
     * 方法功能：活动详情	huodonDetail	ActivityID：活动ID
     */

    public void getHttpData(String id) {
        HttpCallBack.Buider buider = new HttpCallBack.Buider(this);
        buider.setShowLoadding(false);
        buider.setLoadingAndRetryManager(mvpView.getLoadingAndRetryManager());
        buider.setSwipeRefreshLayout(mvpView.getSwipeRefreshLayout());
        HttpCallBack<HttpResult<HuoDongDetailData>> callBack = new HttpCallBack<HttpResult<HuoDongDetailData>>(buider) {
            @Override
            public void onSuccess(HttpResult<HuoDongDetailData> result) {
                super.onSuccess(result);
                if (result.isSucceed()) {
                    mvpView.updataUI(result.getData());
                }

            }
        };

        HttpRequestParam param = new HttpRequestParam("huodonDetail");
        param.addParam("ActivityID", id);
        mvpView.addSubscription(HttpRequest.executeGet(callBack, param));

    }

    /**
     * 作者　　: 李坤
     * 创建时间: 2016/10/26 14:33
     * <p>
     * 方法功能：活动报名	huodongBaoming	ActivityID：活动ID
     */

    public void postBaoming(String ActivityID, final int position) {
        HttpCallBack.Buider buider = new HttpCallBack.Buider(this);
        buider.setHint("正在为您报名");
        HttpCallBack<BaseHttpResponse> callBack = new HttpCallBack<BaseHttpResponse>(buider) {
            @Override
            public void onSuccess(BaseHttpResponse result) {
                super.onSuccess(result);

                if (result.isSucceed()) {
                    mvpView.baomingSuccess(result.getMsg(), position);
                } else {
                    mvpView.showErrorSnackbar(result.getMsg());
                }

            }
        };

        HttpRequestParam param = new HttpRequestParam("huodongBaoming");
        param.addParam("ActivityID", ActivityID);
        mvpView.addSubscription(HttpRequest.executeGet(callBack, param));
    }
}
